package cn.ruituo.adv6;

import java.lang.reflect.Method;

public class CalcTest {
    public static void main(String[] args) throws Exception {
        Caculator c=new Caculator();
        //int r=c.add(40,50);//没有理会这个注解
        //System.out.println(r);
        Method method=c.getClass().getDeclaredMethod("mul",int.class,int.class);
        System.out.println("调用"+method+"方法:");
        if (method.isAnnotationPresent(Log.class)) {
             //存在这个Log的注解
            Log log=method.getDeclaredAnnotation(Log.class);
            System.out.println(log.before());
            System.out.println(method.invoke(c,30,40));
            System.out.println(log.after());
        }else{
            System.out.println(method.invoke(c,30,40));
        }
    }
}
